﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Aribaccio
{
    /// <summary>
    /// 定义扩展Object类
    /// </summary>
    public static class ExtendObject
    {
        /// <summary>
        /// 获取目标对象的成员值
        /// </summary>
        /// <param name="argObject">目标对象</param>
        /// <param name="argMember">成员信息[PropertyInfo、FieldInfo]</param>
        /// <returns></returns>
        public static object? ToTypeValue(this object argObject, MemberInfo argMember)
        {
            if (argMember == null) { return null; }
            if (argMember is PropertyInfo) { return (argMember as PropertyInfo)?.GetValue(argObject, null); }
            else if (argMember is FieldInfo) { return (argMember as FieldInfo)?.GetValue(argObject); }
            else { return null; }
        }
    }
}
